<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<%@ taglib prefix="memberForm" uri="http://www.tongxingzhe.cn/memberForm" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${project == null ? '发布' : '编辑'}项目</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/form.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
                <form id="myForm" class="layui-form mt20" method="post" action="${ctx}/gatherInfo/project/save.do">
                    <input type="hidden" lay-verify="groupIsExpire" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">名称<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="title" lay-verify="title" placeholder="项目名称" class="layui-input"
                                   value="${project.title}">
                            <input type="hidden" name="id" value="${project.id}"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">接送地点<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="place" lay-verify="place" class="layui-input" value="${project.place}">
                        </div>
                    </div>
                    <!-- 				<div class="layui-form-item"> -->
                    <!-- 					<label class="layui-form-label">封面图<span class="f-verify-red">*</span></label> -->
                    <!-- 					<div class="cover-content"> -->
                    <%-- 						<input type="hidden" name="picture" id="pic" lay-verify="picture" value="${project.picture}" /> --%>
                    <%-- 						<c:if test="${project == null || empty project.picture}"> --%>
                    <%-- 							<span id="cover-img" class="cover-img" style="background-image:url(${ctx}/image/posterImg.png)"></span> --%>
                    <%-- 						</c:if> --%>
                    <%-- 						<c:if test="${project != null && not empty project.picture}"> --%>
                    <%-- 							<span id="cover-img" class="cover-img" style="background-image:url('${project.picture}')"></span> --%>
                    <%-- 						</c:if> --%>
                    <!-- 						<div class="u-single-upload"> -->
                    <!-- 							<input type="file" id="upload_single_img" class="u-single-file"> <span class="u-single-upload-icon">+添加封面图</span> -->
                    <!-- 						</div> -->
                    <!-- 					</div> -->
                    <!-- 				</div> -->
                    <div class="layui-form-item">
                        <label class="layui-form-label">基本信息描述<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <!-- 						<script id="ueditor1" type="text/plain" style="width: 800px; height: 200px;"></script> -->
                            <%-- 						<div style="display: none" id="baseInfoView">${project.baseInfoDesc}</div> --%>
                            <!-- 						<input type="hidden" name="baseInfoDesc" id="baseInfoDesc" lay-verify="baseInfoDesc" /> -->
                            <c:if test="${not empty project.baseInfoDesc || null != project.baseInfoDesc}">
                                <textarea name="baseInfoDesc" class="layui-textarea" lay-verify="required"
                                          value="dkfeiwefpwt" placeholder="基本信息描述">${project.baseInfoDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.baseInfoDesc || null == project.baseInfoDesc}">
						<textarea name="baseInfoDesc" class="layui-textarea" lay-verify="required">请完善你的参赛个人基本信息，方便大家更好的认识你，也方便你和大家互相认识
						</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">保险信息描述<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <!-- 						<script id="insuranceUeditor" type="text/plain" style="width: 800px; height: 200px;"></script> -->
                            <%-- 						<div style="display: none" id="insuranceInfoView">${project.insuranceInfoDesc}</div> --%>
                            <!-- 						<input type="hidden" name="insuranceInfoDesc" id="insuranceInfoDesc" lay-verify="insuranceInfoDesc" /> -->
                            <c:if test="${not empty project.insuranceInfoDesc || null != project.insuranceInfoDesc}">
                                <textarea name="insuranceInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="保险信息描述">${project.insuranceInfoDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.insuranceInfoDesc || null == project.insuranceInfoDesc}">
                                <textarea name="insuranceInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="保险信息描述">请完善你个人的保险相关信息，方便赛事组委会为你购买保险，给你的参赛增加更多的保障</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">行程信息描述<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <!-- 						<script id="itineraryUeditor" type="text/plain" style="width: 800px; height: 200px;"></script> -->
                            <%-- 						<div style="display: none" id="itineraryInfoView">${project.itineraryInfoDesc}</div> --%>
                            <!-- 						<input type="hidden" name="itineraryInfoDesc" id="itineraryInfoDesc" lay-verify="itineraryInfoDesc" /> -->
                            <c:if test="${not empty project.itineraryInfoDesc || null != project.itineraryInfoDesc}">
                                <textarea name="itineraryInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="行程信息描述">${project.itineraryInfoDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.itineraryInfoDesc || null == project.itineraryInfoDesc}">
                                <textarea name="itineraryInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="行程信息描述">请完善你的交通出行信息，方便组委会接应您的行程</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">去程说明</label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.goDesc || null != project.goDesc}">
                                <textarea name="goDesc" class="layui-textarea"
                                          placeholder="去程说明">${project.goDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.goDesc || null == project.goDesc}">
                                <textarea name="goDesc" class="layui-textarea" placeholder="去程说明">方便统计和协调各城市出发情况，以及到达时的接机</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">返程说明</label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.backDesc || null != project.backDesc}">
                                <textarea name="backDesc" class="layui-textarea"
                                          placeholder="返程描述">${project.backDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.backDesc || null == project.backDesc}">
                                <textarea name="backDesc" class="layui-textarea"
                                          placeholder="返程描述">方便统计出发时间，便于组委会送机</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">住宿说明</label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.lodgingDesc || null != project.lodgingDesc}">
                                <textarea name="lodgingDesc" class="layui-textarea"
                                          placeholder="住宿说明">${project.lodgingDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.lodgingDesc || null == project.lodgingDesc}">
							<textarea name="lodgingDesc" class="layui-textarea" placeholder="住宿说明">1.组委会统一安排出征仪式晚上和庆功宴晚上的四星级酒店标间住宿，如需安排单间，需补房费
2.提前到达戈友如需，组委会可以协助在活动酒店预定房间</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
                            <a href="${ctx}/gatherInfo/project/list.do" class="layui-btn layui-btn-primary">取消</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!--底部-->
        <%@include file="../include/footer.jsp" %>
        <c:set var="isExpire" value="${memberForm:isExpire(sessionScope.newCurrentUser.id, null)}"/>
    </section>
</div>

<script type="text/javascript" src="${ctxStatic}/UEditor/ueditor.config.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/ueditor.all.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/myplugin/uploadCI.js"></script>
<script type="text/javascript" src="${ctxStatic}/UEditor/myplugin/uploadVideo.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" src="${ctxStatic}/UEditor/lang/zh-cn/zh-cn.js"></script>
<script>

    // 	var ue = UE.getEditor('ueditor1');
    // 	var itineraryUeditor = UE.getEditor('itineraryUeditor');
    // 	var insuranceUeditor = UE.getEditor('insuranceUeditor');

    $(function () {
// 		ue.addListener('ready', function() {
// 			if($("#baseInfoView").html() != "" && $("#baseInfoView").html().length > 200){
// 				this.setHeight(850);
// 			}
// 			this.setContent($("#baseInfoView").html());
// 		});
// 		ue.addListener('blur', function() {
// 			$("#baseInfoView").html(ue.getContent());
// 		});

// 		itineraryUeditor.addListener('ready', function() {
// 			this.setContent($("#itineraryInfoView").html());
// 			if($("#itineraryInfoView").html() != "" && $("#itineraryInfoView").html().length > 200){
// 				this.setHeight(200);
// 			}
// 		});
// 		itineraryUeditor.addListener('blur', function() {
// 			$("#itineraryInfoView").html(itineraryUeditor.getContent());
// 		});

// 		insuranceUeditor.addListener('ready', function() {
// 			this.setContent($("#insuranceInfoView").html());
// 			if($("#insuranceInfoView").html() != "" && $("#insuranceInfoView").html().length > 200){
// 				this.setHeight(200);
// 			}
// 		});
// 		insuranceUeditor.addListener('blur', function() {
// 			$("#insuranceInfoView").html(insuranceUeditor.getContent());
// 		});
        layui.use(['form'], function () {
            var form = layui.form, laydate = layui.laydate;

            //自定义验证规则
            form.verify({
                groupIsExpire: function() {
                    if ('${isExpire}' == 'true' && '${project.id}' == '') {
                        txz.openExpireDialog();
                        return false;
                    }
                    return "";
                },
                title: function (value) {
                    if (value == "") {
                        return '请填写项目名称';
                    }
                },
// 			picture : function(value) {
// 				if (value == "") {
// 					return "请上传项目封面图";
// 				}
// 			},
                baseInfoDesc: function (value) {
                    var content = $("#baseInfoView").html();
                    if (content == "") {
                        return "请填写基本信息描述";
                    }
                },
                itineraryInfoDesc: function (value) {
                    var content = $("#itineraryInfoView").html();
                    if (content == "") {
                        return "请填写行程信息描述";
                    }
                },
                insuranceInfoDesc: function (value) {
                    var content = $("#insuranceInfoView").html();
                    if (content == "") {
                        return "请填写保险信息描述";
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#myForm").attr("action");
                    $.post(action, $('#myForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("提交成功", function () {
                                location.href = "${ctx}/gatherInfo/project/list.do";
                            });
                        } else {
                            util.layerMsgError("提交失败")
                        }
                    })
                });
                return false;
            });
            form.render('radio');
        });
        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：800x450',
                type: '<%=TargetType.GATHER_INFO.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        })
    })

    // 文本编辑器图片上传
    function uEditorUploadCI(editor) {
        txz.openSelImg({
            min: 1,
            type: '<%=TargetType.GATHER_INFO.getCode()%>',
            cb: function (imgs) {
                if (imgs.length) {
                    for (var i = 0, item; i < imgs.length; i++) {
                        item = imgs[i];
                        editor.focus();
                        editor.execCommand('inserthtml', item.htmlStr);
                    }
                }
            }
        })
    }

    function uEditorUploadCIVideo(editor) {
        txz.openSelVideo({
            min: 1,
            type: '<%=TargetType.GATHER_INFO.getCode()%>',
            cb: function (imgs) {
                if (imgs.length) {
                    for (var i = 0, item; i < imgs.length; i++) {
                        item = imgs[i];
                        editor.focus();
                        editor.execCommand('inserthtml', item.htmlStr);
                    }
                }
            }
        })
    }
</script>
<c:if test="${empty project}">
    <script type="text/javascript">
        txz.initHeader({
            nav: [{
                name: '我发布的项目',
                href: '${ctx}/gatherInfo/project/list.do'
            }, {
                name: '编辑项目',
                curr: true
            }],
            btns: [{
                name: '返回',
                icon: 'back',
                href: '${ctx}/gatherInfo/project/list.do'
            }]
        });
    </script>
</c:if>
<c:if test="${not empty project}">
    <script type="text/javascript">
        txz.initHeader({
            nav: [{
                name: '我发布的项目',
                href: '${ctx}/gatherInfo/project/list.do'
            }, {
                name: '发布项目',
                curr: true
            }],
            btns: [{
                name: '返回',
                icon: 'back',
                href: '${ctx}/gatherInfo/project/list.do'
            }]
        });
    </script>
</c:if>
</body>
</html>